package com.ruoyi.lock.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.lock.domain.ALandlord;
import com.ruoyi.lock.mapper.ALandlordMapper;
import com.ruoyi.lock.service.IALandlordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 房东信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-08
 */
@Service
public class ALandlordServiceImpl implements IALandlordService 
{
    @Autowired
    private ALandlordMapper aLandlordMapper;


    /**
     * 查询房东信息
     * 
     * @param id 房东信息主键
     * @return 房东信息
     */
    @Override
    public ALandlord selectALandlordById(Long id)
    {
        ALandlord aLandlord = aLandlordMapper.selectALandlordById(id);
        return aLandlord;
    }

    /**
     * 查询房东信息列表
     * 
     * @param aLandlord 房东信息
     * @return 房东信息
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<ALandlord> selectALandlordList(ALandlord aLandlord)
    {
        return aLandlordMapper.selectALandlordList(aLandlord);
    }

    @Override
    @DataScope(deptAlias = "d")
    public List<ALandlord> selectALandlordList1(ALandlord aLandlord)
    {
        return aLandlordMapper.selectALandlordList1(aLandlord);
    }

    /**
     * 新增房东信息
     * 
     * @param aLandlord 房东信息
     * @return 结果
     */
    @Override
    public int insertALandlord(ALandlord aLandlord)
    {
        Long userId = SecurityUtils.getUserId();
        aLandlord.setCreateTime(DateUtils.getNowDate());
        aLandlord.setCreateBy(String.valueOf(userId));
        return aLandlordMapper.insertALandlord(aLandlord);
    }

    /**
     * 修改房东信息
     * 
     * @param aLandlord 房东信息
     * @return 结果
     */
    @Override
    public int updateALandlord(ALandlord aLandlord)
    {
        Long userId = SecurityUtils.getUserId();
        aLandlord.setUpdateTime(DateUtils.getNowDate());
        aLandlord.setUpdateBy(String.valueOf(userId));
        return aLandlordMapper.updateALandlord(aLandlord);
    }

    /**
     * 批量删除房东信息
     * 
     * @param ids 需要删除的房东信息主键
     * @return 结果
     */
    @Override
    public int deleteALandlordByIds(Long[] ids)
    {
        return aLandlordMapper.deleteALandlordByIds(ids);
    }

    /**
     * 删除房东信息信息
     * 
     * @param id 房东信息主键
     * @return 结果
     */
    @Override
    public int deleteALandlordById(Long id)
    {
        return aLandlordMapper.deleteALandlordById(id);
    }

    /**
     * 查询系统概览的房东数量
     * @return
     */
    @Override
    public Map<String,Integer> selectUserCount() {
        Map<String, Integer> userCount = new HashMap<>();

        int aLandlordCount = aLandlordMapper.selectALandlordCount();
        userCount.put("aLandlordCount",aLandlordCount);


        return userCount;
    }
}
